<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const posts  = [
            {title:'I love JS',author:'joey',id:1},
            {title:'CSS',author:'gigi',id:2},
            {title:'Dev tools webpack',author:'CEO'}
        ];
        const authors =[
            {name:'叶总',hometown:'赣州',bio:'面向字节跳动编程'}
        ]
        function getPostById(id){
            // id 找到文章
            // const post = posts.find(post =>post.id === id)
            // const{ author } = post;
            // console.log(authors.find(item => item.name === author))
            // return post
            return new Promise((resolve,reject)=>{
                console.log('---------')
                setTimeout(()=>{
                    const post = posts.find(post => post.id ===id);
                    console.log(post)
                    if(post){
                        resolve(data);
                    }else{
                        let err = new Error('没有数据')
                        reject(err)
                    }
                },200)
            })
        }
        getPostById(10)
            .then((data)=>{
                console.log(data,'////////////')
            })
            .catch((err)=>{
                console.log(err.message)
            })
    </script>
</body>
</html>